/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.app.model;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Thuan
 */
@Entity
@Table(name = "SubjectOfCourse")
@NamedQueries({
    @NamedQuery(name = "SubjectOfCourse.findAll", query = "SELECT s FROM SubjectOfCourse s"),
    @NamedQuery(name = "SubjectOfCourse.findBySubjectId", query = "SELECT s FROM SubjectOfCourse s WHERE s.subjectOfCoursePK.subjectId = :subjectId"),
    @NamedQuery(name = "SubjectOfCourse.findByCourseId", query = "SELECT s FROM SubjectOfCourse s WHERE s.subjectOfCoursePK.courseId = :courseId"),
    @NamedQuery(name = "SubjectOfCourse.findBySemesterId", query = "SELECT s FROM SubjectOfCourse s WHERE s.subjectOfCoursePK.semesterId = :semesterId")})
public class SubjectOfCourse implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected SubjectOfCoursePK subjectOfCoursePK;
    @JoinColumn(name = "subjectId", referencedColumnName = "subjectId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Subject subject;
    @JoinColumn(name = "semesterId", referencedColumnName = "semesterId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Semester semester;
    @JoinColumn(name = "courseId", referencedColumnName = "courseId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Course course;

    public SubjectOfCourse() {
    }

    public SubjectOfCourse(SubjectOfCoursePK subjectOfCoursePK) {
        this.subjectOfCoursePK = subjectOfCoursePK;
    }

    public SubjectOfCourse(int subjectId, int courseId, int semesterId) {
        this.subjectOfCoursePK = new SubjectOfCoursePK(subjectId, courseId, semesterId);
    }

    public SubjectOfCoursePK getSubjectOfCoursePK() {
        return subjectOfCoursePK;
    }

    public void setSubjectOfCoursePK(SubjectOfCoursePK subjectOfCoursePK) {
        this.subjectOfCoursePK = subjectOfCoursePK;
    }

    public Subject getSubject() {
        return subject;
    }

    public void setSubject(Subject subject) {
        this.subject = subject;
    }

    public Semester getSemester() {
        return semester;
    }

    public void setSemester(Semester semester) {
        this.semester = semester;
    }

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (subjectOfCoursePK != null ? subjectOfCoursePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SubjectOfCourse)) {
            return false;
        }
        SubjectOfCourse other = (SubjectOfCourse) object;
        if ((this.subjectOfCoursePK == null && other.subjectOfCoursePK != null) || (this.subjectOfCoursePK != null && !this.subjectOfCoursePK.equals(other.subjectOfCoursePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.app.model.SubjectOfCourse[ subjectOfCoursePK=" + subjectOfCoursePK + " ]";
    }

}
